import 'package:get/get.dart';

abstract class BaseFilterItem {
  final String key;
  final String title;
  final RxBool isSelected;
  final List<BaseFilterItem> children;
  final BaseFilterItem? custom;
  final String type;
  String? value;

  BaseFilterItem({
    required this.key,
    required this.title,
    required this.type,
    this.value,
    required this.children,
    this.custom,
    bool initialSelected = false,
  }) : isSelected = initialSelected.obs;

  void toggleSelection() => isSelected.toggle();
}

/// 基础值类型项
class ValueFilterItem extends BaseFilterItem {
  final dynamic rawValue;

  ValueFilterItem({
    required super.key,
    required super.title,
    required this.rawValue,
    required super.type,
    super.value,
    super.children = const [],
    super.custom,
    super.initialSelected,
  });
}

/// 范围选择项
class RangeFilterItem extends BaseFilterItem {
  final RxDouble currentMin;
  final RxDouble currentMax;
  final double defaultMin;
  final double defaultMax;

  RangeFilterItem({
    required super.key,
    required super.title,
    required super.type,
    required this.defaultMin,
    required this.defaultMax,
    BaseFilterItem? custom,
  })  : currentMin = defaultMin.obs,
        currentMax = defaultMax.obs,
        super(
          children: const [],
          custom: custom,
        );
}

/// 输入类型项
class InputFilterItem extends BaseFilterItem {
  final RxString inputValue = ''.obs;
  final String? hintText;

  InputFilterItem({
    required super.key,
    required super.title,
    this.hintText,
    super.value = "",
    super.children = const [],
    required super.type,
  });
}
